home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / BasicIconFactory.java < prev    next >
Text File  |  1998-06-30  |  7KB  |  222 lines

  1. /*
  2.  * @(#)BasicIconFactory.java    1.15 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.basic;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.plaf.UIResource;
  25.  
  26. import java.awt.Graphics;
  27. import java.awt.Color;
  28. import java.awt.Component;
  29. import java.awt.Polygon;
  30. import java.io.Serializable;
  31.  
  32. /**
  33.  * Factory object that can vend Icons appropriate for the basic L & F.
  34.  * <p>
  35.  * Warning: serialized objects of this class will not be compatible with
  36.  * future swing releases.  The current serialization support is appropriate 
  37.  * for short term storage or RMI between Swing1.0 applications.  It will
  38.  * not be possible to load serialized Swing1.0 objects with future releases
  39.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  40.  * baseline for the serialized form of Swing objects.
  41.  *
  42.  * @version 1.15 02/02/98
  43.  * @author David Kloba
  44.  * @author Georges Saab
  45.  */
  46. public class BasicIconFactory implements Serializable
  47. {
  48.     private static Icon frame_icon;
  49.     private static Icon checkBoxIcon;
  50.     private static Icon radioButtonIcon;
  51.     private static Icon checkBoxMenuItemIcon;
  52.     private static Icon radioButtonMenuItemIcon;
  53.     private static Icon menuItemCheckIcon;
  54.     private static Icon menuItemArrowIcon;
  55.     private static Icon menuArrowIcon;
  56.  
  57.     public static Icon getMenuItemCheckIcon() {
  58.     if (menuItemCheckIcon == null) {
  59.         menuItemCheckIcon = new MenuItemCheckIcon();
  60.     }
  61.     return menuItemCheckIcon;
  62.     }
  63.  
  64.     public static Icon getMenuItemArrowIcon() {
  65.     if (menuItemArrowIcon == null) {
  66.         menuItemArrowIcon = new MenuItemArrowIcon();
  67.     }
  68.     return menuItemArrowIcon;
  69.     }
  70.  
  71.     public static Icon getMenuArrowIcon() {
  72.     if (menuArrowIcon == null) {
  73.         menuArrowIcon = new MenuArrowIcon();
  74.     }
  75.     return menuArrowIcon;
  76.     }
  77.  
  78.     public static Icon getCheckBoxIcon() {
  79.     if (checkBoxIcon == null) {
  80.         checkBoxIcon = new CheckBoxIcon();
  81.     }
  82.     return checkBoxIcon;
  83.     }
  84.  
  85.     public static Icon getRadioButtonIcon() {
  86.     if (radioButtonIcon == null) {
  87.         radioButtonIcon = new RadioButtonIcon();
  88.     }
  89.     return radioButtonIcon;
  90.     }
  91.  
  92.     public static Icon getCheckBoxMenuItemIcon() {
  93.     if (checkBoxMenuItemIcon == null) {
  94.         checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
  95.     }
  96.     return checkBoxMenuItemIcon;
  97.     }
  98.  
  99.     public static Icon getRadioButtonMenuItemIcon() {
  100.     if (radioButtonMenuItemIcon == null) {
  101.         radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
  102.     }
  103.     return radioButtonMenuItemIcon;
  104.     }
  105.  
  106.     public static Icon createEmptyFrameIcon() {
  107.     if(frame_icon == null)
  108.         frame_icon = new EmptyFrameIcon();
  109.     return frame_icon;
  110.     }
  111.  
  112.     private static class EmptyFrameIcon implements Icon, Serializable {
  113.         int height = 16;
  114.         int width = 14;
  115.         public void paintIcon(Component c, Graphics g, int x, int y) {
  116.         }
  117.         public int getIconWidth() { return width; }
  118.         public int getIconHeight() { return height; }
  119.     };
  120.  
  121.     private static class CheckBoxIcon implements Icon, Serializable
  122.     {
  123.     final static int csize = 13;
  124.     public void paintIcon(Component c, Graphics g, int x, int y) {
  125.     }
  126.  
  127.     public int getIconWidth() {
  128.         return csize;
  129.     }
  130.         
  131.     public int getIconHeight() {
  132.         return csize;
  133.     }
  134.     }
  135.  
  136.     private static class RadioButtonIcon implements Icon, UIResource, Serializable
  137.     {
  138.     public void paintIcon(Component c, Graphics g, int x, int y) {
  139.     }
  140.  
  141.     public int getIconWidth() {
  142.         return 13;
  143.     }
  144.         
  145.     public int getIconHeight() {
  146.         return 13;
  147.     }
  148.     } // end class RadioButtonIcon
  149.  
  150.  
  151.     private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable 
  152.     {
  153.     public void paintIcon(Component c, Graphics g, int x, int y) {
  154.         AbstractButton b = (AbstractButton) c;
  155.         ButtonModel model = b.getModel();
  156.         boolean isSelected = model.isSelected();
  157.         if (isSelected) {
  158.         y = y - getIconHeight() / 2;
  159.         y += 2;
  160.         g.drawLine(x+9, y+3, x+9, y+3);
  161.         g.drawLine(x+8, y+4, x+9, y+4);
  162.         g.drawLine(x+7, y+5, x+9, y+5);
  163.         g.drawLine(x+6, y+6, x+8, y+6);
  164.         g.drawLine(x+3, y+7, x+7, y+7);
  165.         g.drawLine(x+4, y+8, x+6, y+8);
  166.         g.drawLine(x+5, y+9, x+5, y+9);
  167.         g.drawLine(x+3, y+5, x+3, y+5);
  168.         g.drawLine(x+3, y+6, x+4, y+6);
  169.         }
  170.     }
  171.     public int getIconWidth() { return 9; }
  172.     public int getIconHeight() { return 9; }
  173.  
  174.     } // End class CheckBoxMenuItemIcon
  175.  
  176.     
  177.     private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable 
  178.     {
  179.     public void paintIcon(Component c, Graphics g, int x, int y) {
  180.         AbstractButton b = (AbstractButton) c;
  181.         ButtonModel model = b.getModel();
  182.         if (b.isSelected() == true) {
  183.         g.fillArc(2,4,getIconWidth()-2, getIconHeight()-2, 0, 360);
  184.         }
  185.     }
  186.         public int getIconWidth() { return 9; }  // was 12
  187.     public int getIconHeight() { return 9; }
  188.  
  189.     } // End class RadioButtonMenuItemIcon
  190.  
  191.  
  192.     private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{
  193.     public void paintIcon(Component c, Graphics g, int x, int y) {
  194.     }
  195.     public int getIconWidth() { return 9; }
  196.     public int getIconHeight() { return 9; }
  197.  
  198.     } // End class MenuItemCheckIcon
  199.  
  200.     private static class MenuItemArrowIcon implements Icon, UIResource, Serializable {
  201.     public void paintIcon(Component c, Graphics g, int x, int y) {
  202.     }
  203.     public int getIconWidth() { return 4; }
  204.     public int getIconHeight() { return 8; }
  205.  
  206.     } // End class MenuItemArrowIcon
  207.  
  208.     private static class MenuArrowIcon implements Icon, UIResource, Serializable {
  209.     public void paintIcon(Component c, Graphics g, int x, int y) {
  210.         Polygon p = new Polygon();
  211.         p.addPoint(x, y);
  212.         p.addPoint(x+getIconWidth(), y+getIconHeight()/2);
  213.         p.addPoint(x, y+getIconHeight());
  214.         g.fillPolygon(p);
  215.  
  216.     }
  217.     public int getIconWidth() { return 4; }
  218.     public int getIconHeight() { return 8; }
  219.     } // End class MenuArrowIcon
  220. }
  221.  
  222.